#include "level1.h"

Level1::Level1(QWidget *parent)
    : LevelScene(QPixmap(RESOURCE_DIR + "/Rose_Past_Map.png"),QImage(RESOURCE_DIR + "/Rose_Past_Mask.png"), parent)
{
    buildingImage = new GameBackground(QPixmap(RESOURCE_DIR + "/Rose_Past_Buildings.png"),mainScene);
    buildingImage->setZValue(1);

    river = new River(QPixmap(RESOURCE_DIR + "/1water1.png"),mainScene,this);
    QObject::connect(river,SIGNAL(clicked()),this,SLOT(riverClicked()));
    QObject::connect(river,SIGNAL(hoverChanged(bool)),this,SLOT(riverHoverChanged(bool)));

    // Add the tools
    quarantineTool = addTool(15, QString("Quarantene (Place road block)"),RESOURCE_DIR + "/buttons/Dean_RoadBlock.png");
    sterilizationTool = addTool(5,QString("Sterilize building"),RESOURCE_DIR + "/buttons/Dean_Sterilize.png");
    cleanWaterTool = addTool(300,QString("Clean city water supply"),RESOURCE_DIR + "/buttons/Dean_CleanWater.png");
    coughSyrupTool = addTool(5,QString("Give people in a building cough syrup"),RESOURCE_DIR + "/buttons/Dean_CoughSyrup.png");
    bonesetExtractTool = addTool(5,QString("Give people in a building Boneset extract"),RESOURCE_DIR + "/buttons/Dean_Boneset.png");
    placeboTool = addTool(5,QString("Give people in a building a placebo drug"),RESOURCE_DIR + "/buttons/Dean_Placebo.png");

    // Add one story houses
    QPointF house1Info[22][2] = {{QPointF(776,476),QPointF(78,50)},
                                 {QPointF(841,476),QPointF(88,50)},
                                 {QPointF(776,541),QPointF(80,58)},
                                 {QPointF(841,541),QPointF(86,58)},
                                 {QPointF(926,621),QPointF(93,65)},
                                 {QPointF(990,621),QPointF(103,64)},
                                 {QPointF(926,686),QPointF(95,73)},
                                 {QPointF(990,686),QPointF(101,73)},
                                 {QPointF(1077,621),QPointF(108,65)},
                                 {QPointF(1141,621),QPointF(118,65)},
                                 {QPointF(1077,686),QPointF(110,73)},
                                 {QPointF(1141,686),QPointF(116,73)},
                                 {QPointF(926,771),QPointF(93,80)},
                                 {QPointF(990,771),QPointF(103,80)},
                                 {QPointF(926,836),QPointF(95,88)},
                                 {QPointF(990,836),QPointF(101,88)},
                                 {QPointF(841,621),QPointF(88,65)},
                                 {QPointF(841,686),QPointF(86,73)},
                                 {QPointF(926,1136),QPointF(95,118)},
                                 {QPointF(990,1136),QPointF(101,118)},
                                 {QPointF(1077,1136),QPointF(110,118)},
                                 {QPointF(1141,1136),QPointF(116,118)}
                                 };

    for (unsigned int index = 0; index < (sizeof(house1Info)/(sizeof(*house1Info[0])*2)); index++)
    {
        char buildingColor = '1' + (rand() % 4);
        addBuilding(QPoint(house1Info[index][1].toPoint()),QPointF(house1Info[index][0]),QPixmap(RESOURCE_DIR + "/buildings/Rose_1home" + buildingColor + ".png"));
    }

    // Add two story houses
    QPointF house2Info[6][2] = {{QPointF(927,522),QPointF(95,58)},
                                {QPointF(992,522),QPointF(102,58)},
                                {QPointF(1076,522),QPointF(110,59)},
                                {QPointF(1141,522),QPointF(116,59)},
                                {QPointF(1226,822),QPointF(125,89)},
                                {QPointF(1291,822),QPointF(131,89)}
                                };

    for (unsigned int index = 0; index < (sizeof(house2Info)/(sizeof(*house2Info[0])*2)); index++)
    {
        char buildingColor = '1' + (rand() % 4);
        addBuilding(QPoint(house2Info[index][1].toPoint()),QPointF(house2Info[index][0]),QPixmap(RESOURCE_DIR + "/buildings/Rose_2home" + buildingColor + ".png"));
    }

    // Add three story houses
    QPointF house3Info[3][2] = {{QPointF(1222,472),QPointF(131,57)},
                                {QPointF(1222,922),QPointF(131,102)},
                                {QPointF(1222,1072),QPointF(131,117)}
                                };

    for (unsigned int index = 0; index < (sizeof(house3Info)/(sizeof(*house3Info[0])*2)); index++)
    {
        char buildingColor = '1' + (rand() % 4);
        addBuilding(QPoint(house3Info[index][1].toPoint()),QPointF(house3Info[index][0]),QPixmap(RESOURCE_DIR + "/buildings/Rose_3home" + buildingColor + ".png"));
    }

    // Add stores
    QPointF storesInfo[16][2] = {{QPointF(776,627),QPointF(79,65)},
                                 {QPointF(776,692),QPointF(79,72)},
                                 {QPointF(776,778),QPointF(79,81)},
                                 {QPointF(776,843),QPointF(79,87)},

                                 {QPointF(774,928),QPointF(79,96)},
                                 {QPointF(774,996),QPointF(79,103)},
                                 {QPointF(839,928),QPointF(86,96)},
                                 {QPointF(839,996),QPointF(86,103)},

                                 {QPointF(774,1078),QPointF(79,111)},
                                 {QPointF(774,1146),QPointF(79,118)},
                                 {QPointF(839,1078),QPointF(86,111)},
                                 {QPointF(839,1146),QPointF(86,118)},

                                 {QPointF(924,1078),QPointF(94,111)},
                                 {QPointF(989,1078),QPointF(101,111)},
                                 {QPointF(1074,1078),QPointF(109,111)},
                                 {QPointF(1139,1078),QPointF(116,111)},
                                };

    for (unsigned int index = 0; index < (sizeof(storesInfo)/(sizeof(*storesInfo[0])*2)); index++)
    {
        char buildingColor = '1' + (rand() % 3);
        addBuilding(QPoint(storesInfo[index][1].toPoint()),QPointF(storesInfo[index][0]),QPixmap(RESOURCE_DIR + "/buildings/1Store" + buildingColor + ".png"));
    }

    // Add other buildings
    addBuilding(QPoint(88,87),QPointF(841,800),QPixmap(RESOURCE_DIR + "/buildings/1PostOffice.png"));
    addBuilding(QPoint(93,103),QPointF(920,935),QPixmap(RESOURCE_DIR + "/buildings/1FireStation.png"));
    addBuilding(QPoint(113,87),QPointF(1085,775),QPixmap(RESOURCE_DIR + "/buildings/1CityHall-Courthouse1.png"));
    addBuilding(QPoint(117,97),QPointF(1075,915),QPixmap(RESOURCE_DIR + "/buildings/1policestation1.png"));
    addBuilding(QPoint(132,70),QPointF(1219,616.5),QPixmap(RESOURCE_DIR + "/buildings/1school2-big.png"));
    addBuilding(QPoint(109,103),QPointF(1073,988),QPixmap(RESOURCE_DIR + "/buildings/1Bank.png"));

    QString convertString;

    for (int count = 0; count<600; count ++)
    {
        convertString.setNum((rand()%12) + 1);
        addPerson(QPixmap(RESOURCE_DIR + "/people/Dean_Person" + convertString + ".png"),buildings.at(rand() % buildings.length()));
    }
    for (int count = 0; count<8; count ++)
    {
        convertString.setNum((rand()%12) + 1);
        int r = rand() % 3;
        if (r == 0)
            addPerson(QPixmap(RESOURCE_DIR + "/people/Dean_Person" + convertString + ".png"),buildings.at(0));
        else if (r == 1)
            addPerson(QPixmap(RESOURCE_DIR + "/people/Dean_Person" + convertString + ".png"),buildings.at(1));
        else
            addPerson(QPixmap(RESOURCE_DIR + "/people/Dean_Person" + convertString + ".png"),buildings.at(2));
        people.last()->virus = new Virus(400,350,250,0,people.last());
    }

    healthyCountThreshold = people.length() - 50;
    healthyTimeThreshold = QTime(0,2,0,0);

    maxPeopleOnStreet = 25;
    currentLevel = levelScene1;
}
